<template>
    <div class="user">
        <div class="list">
            <div class="serach">
                <input type="text" placeholder="搜索企业名称或用户姓名">
            </div>
          <div class="user-list-outer">
              <ul class="user-list">
                  <!--isTalking-->
                  <li class="user-item "  @click="changeChatObject(user)" v-for="user in chatList" :class="{isTalking:user.isTalking}">
                      <dl>
                          <dt class="pic">
                              <span class="circle" v-if="user.unreadMessageNumber>0"></span>
                              <img :src="user.portraitUri" :class="{OffLine:user.status == 1}" alt="">
                          </dt>
                          <dd class="content">
                              <p>{{user.name}}</p>
                              <p>
                                  <span class="messge" v-html="user.content" v-if="user.msgType == 'RC:TxtMsg'"></span>
                                  <span class="messge"  v-if="user.msgType == 'RC:ImgMsg'"> [图片]</span>
                                  <span class="messge" v-if="user.msgType == 'RC:FileMsg'">[文件]</span>
                                  <span class="time">{{user.sendTime | userTimeFilter}}</span>
                              </p>
                          </dd>
                      </dl>
                  </li>
            </ul>
          </div>
        </div>
    </div>
</template>

<script>
 import User from './../service/User-Service'
 import RonrIM from './../service/RoneIM -Service'
 const _RonrIM = new RonrIM();
 const  _User = new User();
  export default {
    data () {
      return {
        chatList:this.$store.state.chatList,
        params:{
         code:this.$util.getQueryString('code') //D3C8A8E486C7460B949A3A57A089A5D7
        }
      }
    },
    created(){

    },
    mounted(){

    },
    methods:{
      changeChatObject(chatItem){
        _User.setUserDataInit(this.chatList,'isTalking');
        chatItem.isTalking = true;
        this.$util.setSessionStorage('targetId',chatItem.code);
        chatItem.unreadMessageNumber = 0;
        _RonrIM.clearUnreadCount(chatItem.code).then(()=>{
          console.log('清除成功')
          _RonrIM.getTotalUnreadCount().then((count)=>{
            console.log(count)
            this.$store.dispatch('changeUnReadMessageNumber',count);
          })
        })

        this.$store.dispatch('changeChatObject',chatItem);
      },
      _setUserStatus(){
        this.chatList.forEach((item)=>{
          let params = {
            code:item.code
          };
          _User.setUserStatus(params).then((status)=>{
            item.status = status;
          })
        })
      }
    },
    computed: {
      getUserListData() {
        return this.$store.state.chatList;
      }
    },
    watch: {
      getUserListData: function(a, b) {
        this.chatList = a;
        this._setUserStatus();
      }
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss" type="text/scss">
    .user{
        overflow: hidden;
        height:100%;
        float: left;
        width: 100%;
        background: #fff;
        box-sizing: border-box;
        border-right: 1px solid red;
        .title{
            width: 150px;
            height: 100%;
            box-sizing: border-box;
            background: #5187C2;
            padding-top: 15px;
            float: left;
            .headPortrait{
                img{
                    width: 40px;
                    height: 40px;
                }
            }
            .user-name{
                margin-top: 10px;
                font-size: 12px;
                color: #ffffff;
            }
        }
        .list{
            width: 100%;
            height: 100%;
            .serach{
                width: 100%;
                height: 44px;
                display: flex;
                justify-content: center;
                align-items: center;
                background: #FBFBFB;
                border-bottom:1px solid #C7C4C4;
                input{
                    width: 180px;
                    height: 30px;
                    border: 1px solid #EDEDED;
                    padding-left: 10px;
                }
            }
            .user-list-outer{
                width: 100%;
                height: 100%;
            }
            .user-list{
                width: 100%;
                -ms-overflow-style:none;
                /*火狐下隐藏滚动条*/
                margin-bottom: 70px;
                .user-item{
                    cursor:pointer;
                    height: 50px;
                    padding: 6px 5px 6px 10px;

                    border-bottom: 1px solid #C7C4C4;
                    dl{
                        width: 100%;
                        height: 100%;
                        .pic{
                            float: left;
                            width: 40px;
                            position: relative;
                            .circle{
                                position: absolute;
                                right:0;
                                top: -2px;
                                display: inline-block;
                                width: 10px;
                                height: 10px;
                                background: red;
                                border-radius: 10px;
                                z-index: 12;
                            }
                            img{
                                width:40px;
                                height: 40px;
                            }
                            .OffLine {
                                -webkit-filter: grayscale(100%);
                                -moz-filter: grayscale(100%);
                                -ms-filter: grayscale(100%);
                                -o-filter: grayscale(100%);
                                filter: grayscale(100%);
                                filter: gray;
                            }
                        }
                        .content{
                            width: 80%;
                            height: 40px;
                            float: right;

                            p:nth-child(1){
                                height: 20px;
                                line-height: 20px;
                                margin-bottom: 5px;
                                text-align: left;
                                overflow:hidden;
                                text-overflow:ellipsis;
                                white-space:nowrap;
                                font-size: 14px;
                                color: #000000;
                                font-weight:bolder;
                            }
                            p:nth-child(2){
                                width: 100%;
                                height: 24px;
                                line-height: 10px;
                                .messge{
                                    width: 80px;
                                    float: left;
                                    text-align: left;
                                    overflow:hidden;
                                    text-overflow:ellipsis;
                                    white-space:nowrap;
                                    font-size: 13px;
                                    color: #636161;
                                    height: 24px;
                                    line-height: 24px;
                                }
                                .time{
                                    float: right;
                                    width: 60px;
                                    overflow: hidden;
                                    height: 20px;
                                    text-align: right;
                                    line-height: 10px;
                                    font-size: 12px;
                                    color: #636161;
                                }
                            }
                        }
                    }

                }
                .isTalking{
                    background: #EDEDED;
                }
            }
            .user-list-outer::-webkit-scrollbar{
                //display: none;

            }

        }
    }
</style>
